package pl.mmadej.ds4java.ds.common;


//not allowing nulls
public class Node<T> {

    private T value;

    public Node(T value) {
        assertNotNull(value);
        this.value = value;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        assertNotNull(value);
        this.value = value;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Node node = (Node) o;
        return value.equals(node.value);  //cannot be null because of constructor and setter
    }

    @Override
    public int hashCode() {
        return value.hashCode();  //cannot be null because of constructor and setter
    }

    @Override
    public String toString() {
        return "Node[" + value + "]";
    }

    private void assertNotNull(Object o) {
        if (o == null) {
            throw new NullPointerException();
        }
    }
}
